﻿using System;
using System.Collections.Generic;
using System.IO;

namespace BotDetector.Core
{
    class Program
    {
        static string nonspamTestFolderPath = "nonbot-test";
        static string spamTestFolderPath = "bot-test";

        private static Detector detector;
        private static int correct, total;
        static void Main(string[] args)
        {
            nonspamTestFolderPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory)))) + @"\ClassifierData\nonbot-test";
            spamTestFolderPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory)))) + @"\ClassifierData\bot-test";

            detector = new Detector();
            
            List<string> spamTestList = InitSpamTests();
            List<string> nonspamTestList = InitNonspamTests();

            foreach (string spamText in spamTestList)
            {
                double rez = detector.Classify(spamText);

                if (rez > 0.5) correct += 1;
                total += 1;
                Console.WriteLine(total);
            }

            foreach (string nonspamText in nonspamTestList)
            {
                double rez = detector.Classify(nonspamText);
                if (rez < 0.5) correct += 1;
                total += 1;
                Console.WriteLine(total);
            }

            Console.WriteLine(correct + " " + total);
            Console.ReadKey();
        }

        static List<string> InitSpamTests()
        {
            List<string> spamList = new List<string>();
            foreach (string file in Directory.EnumerateFiles(spamTestFolderPath))
            {

                spamList.Add(File.ReadAllText(file));
            }
            return spamList;
        }

        static List<string> InitNonspamTests()
        {
            List<string> nonspamList = new List<string>();
            foreach (string file in Directory.EnumerateFiles(nonspamTestFolderPath))
            {
                nonspamList.Add(File.ReadAllText(file));
            }
            return nonspamList;
        }
    }
}
